package Dinamica.src;
import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class pacial_robbery_GAB {
	
	public static int[][][] matriz = new int[101][100][100];
	public static int tiempoT = 0, c, f;
	public static List<int[]> posibles[];
	public static List<int[]> camino[];
	public static boolean encontrado = false, escapado = true;

	
	
	
	static class info {
		public int c1;
		public int f1;
		public int c2;
		public int f2;

		public info(int c1, int f1, int f2, int c2) {
			this.c1 = c1;
			this.c2 = c2;
			this.f1 = f1;
			this.f2 = f2;
		}

		public String toString() {
			return " f1 " + f1 + " c1 " + c1 + " f2 " + f2 + " c2 " + c2 + "\n";
		}
	}
	
	

	public static void llenar(int[][] memo, info in) {
		for (int i = in.f1; i <= in.f2; i++) {
			for (int j = in.c1; j <= in.c2; j++) {
				if ((i == in.f1 || i == in.f2 || j == in.c1 || j == in.c2)
						&& memo[i][j] != 1) {
					memo[i][j] = 2;
				} else {
					memo[i][j] = 1;
				}
			}
		}
	}
	
	

	public static  List<int[]> disponibles(int memo[][]){
		List<int[]> l=new ArrayList<int[]>(100);
		for (int i = 1; i < memo.length; i++) {
			for (int j = 1; j < memo[i].length; j++) {
				if(memo[i][j]==0){
					l.add(new int[]{i,j});
				}
				if(memo[i][j]==2){
					memo[i][j]=0;
				}
			}
		}
		return l;
		
	}

	public static void main(String[] args) throws Throwable {
		BufferedReader br = new BufferedReader(new FileReader("robbery.in"));
		String line = null;
		int rob = 0;
		while ((line = br.readLine()) != null) {
			rob++;
			StringTokenizer st = new StringTokenizer(line);
			f = Integer.parseInt(st.nextToken());
			c = Integer.parseInt(st.nextToken());
			int t = Integer.parseInt(st.nextToken());
			tiempoT = t;
			if (c == 0 && f == 0 && t == 0)
				break;

			int n = Integer.parseInt(br.readLine());

			List<info> informes[] = new List[t+1];
			for (int i = 1; i < informes.length; i++) {
				informes[i]=new ArrayList<info>(100);
			}
			
			for (int i = 0; i < n; i++) {
				String u = br.readLine();
				st = new StringTokenizer(u);
				int tem = Integer.parseInt(st.nextToken());
				List<info> l = informes[tem];
				//left
				int c1=Integer.parseInt(st.nextToken());
				//top
				int f1=Integer.parseInt(st.nextToken());
				//rigth
				int c2=Integer.parseInt(st.nextToken());
				//button
				int f2=Integer.parseInt(st.nextToken());
				l.add(new info(f1, c1, c2,f2));
			}
			// System.out.println(l);
			int memo[][] = new int[f + 1][c + 1];
			
			posibles =new List[t+1];
			camino = new List[t+1];

			for (int i = 1; i < posibles.length; i++) {
				posibles[i]=new ArrayList<int[]>();
			}
			
			//Para t=1
			List<info> t1=informes[1];
			for (info it : t1) {
				llenar(memo, it);
			}
			
			posibles[1]=disponibles(memo);
			for (int i = 2; i < posibles.length; i++) {
				List<info>tem=informes[i];
				if(tem.size()!=0){
					for (info it :tem) {
						llenar(memo,it);
					}
				}
				posibles[i]=disponibles(memo);
			}
			
			System.out.println("Robbery #"+rob+":");
			encontrado = false; escapado = false;
			List<int[]> tem=posibles[1];
			for (int[] it : tem) {
				if(encontrado) break;
				System.out.println(matriz[100][0][0]);
				if(f(it[0],it[1],1) == 10){
					for(int i=1; i!=tiempoT; i++){
						if(matriz[100][0][i]==1)
							System.out.println("Time step "+i+": The robber has been at "+matriz[100][1][i]+","+matriz[100][2][i]+".");
					}
				}
				else if(escapado){
					System.out.println("The robber has escaped.");
				}
				else System.out.println("Nothing known.");
			}
			System.out.println("");
			
			
			for (int i = 1; i < posibles.length; i++) {
				List<int[]> tem1=posibles[i];
				System.out.println("en el tiempo t = "+i+ " :");
				for (int[] it : tem1) {
					System.out.println(Arrays.toString(it));
				}
			}
			
			
			//System.out.println(posibles[1]);
			
		}
	}
	
	public static boolean contiene(int i, int j, int t){
		List<int[]> tem=posibles[t];
		int[] busca = {i,j};
		if(tem.size()==0) {
			escapado = true;
			encontrado = true;
			return false;
		}
		for(int[] it: tem){
			if(it[0]==busca[0] && it[1]==busca[1]) return true;
		}
		return false;
	}
	
	
	public static int f(int i, int j, int t){
		if(matriz[i][j][t] != 0) return matriz[i][j][t];
		
		if(t==tiempoT && contiene(i,j,t)){
			matriz[i][j][t] = 10;
			//System.out.println("Llegue al fondo: i "+i+" j "+j+" t "+t);
			matriz[100][0][t]++;
			matriz[100][0][0]++;
			matriz[100][1][t] = i;
			matriz[100][2][t] = j;
			encontrado = true;
			return 10;
		}
		
		if(!contiene(i,j,t)){
			matriz[i][j][t] = -1;
			return -1;
		}
		
		matriz[i][j][t] = 1;
		int iz = 0, de = 0, ar = 0, ab = 0, cen = 0;
		if(i-1>0) iz = f(i-1,j,t+1);
		if(i+1<c) de = f(i+1,j,t+1);
		if(j-1>0) ab = f(i,j-1,t+1);
		if(j+1<f) de = f(i,j+1,t+1);
		cen = f(i,j,t+1);
		
				
		if(iz==10 || de==10 || ar==10 || ab==10 || cen==10){
			matriz[i][j][t] = 10;
			//System.out.println("Recibi un 10 :D i "+i+" j "+j+" t "+t);
			matriz[100][0][t]++;
			matriz[100][0][0]++;
			matriz[100][1][t] = i;
			matriz[100][2][t] = j;
			
			return 10;
		}
		
		return matriz[i][j][t];
		
	}
	
}




